package com.zz.cinema.dao.impl;

import org.springframework.stereotype.Repository;

import com.zz.cinema.dao.ITS_MovieDao;
import com.zz.cinema.domain.TS_Movie;
import com.zz.cinema.util.PageList;

@Repository("movieDao")
public class TS_MovieDaoImpl extends TS_BaseDaoImpl5 implements ITS_MovieDao {

	@Override
	public boolean saveMovie(TS_Movie movie) {
		saveObject(movie);
		return true;
	}

	@Override
	public TS_Movie updateMovie(TS_Movie movie) {
		updateObject(movie);
		return movie;
	}

	@Override
	public boolean deleteMovie(int id) {
		TS_Movie movie = null;
		try {
			movie = (TS_Movie) findList("from TS_Movie m where m.movieId = ?", id).get(0);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		getSession().delete(movie);
		return true;
	}

	@Override
	public TS_Movie getMovie(int id) {

		return findObject(TS_Movie.class, id);
	}

	@Override
	public PageList<TS_Movie> getPage(int page) {
		int rows = 4;
		PageList<TS_Movie> pageList = findPageList("from TS_Movie m order by m.movieId asc", page, rows);
		return pageList;
	}

}
